home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / assignment.e < prev    next >
Text File  |  1998-01-16  |  9KB  |  343 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class ASSIGNMENT
  17. --
  18. -- For instruction like :
  19. --                          foo := bar;
  20. --                          foo := bar + 1;
  21. --
  22. -- 
  23.  
  24. inherit INSTRUCTION;
  25.    
  26. creation make
  27.    
  28. feature 
  29.    
  30.    left_side: EXPRESSION;
  31.    
  32.    right_side: EXPRESSION;
  33.    
  34. feature
  35.  
  36.    make(ls: like left_side; rs: like right_side) is
  37.       require
  38.      ls.is_writable;
  39.      ls.start_position /= Void;
  40.      rs /= Void
  41.       do
  42.      left_side := ls;
  43.      right_side := rs;
  44.       ensure
  45.      left_side = ls;
  46.      right_side = rs
  47.       end; 
  48.    
  49. feature
  50.    
  51.    end_mark_comment: BOOLEAN is false;
  52.  
  53. feature
  54.    
  55.    is_pre_computable: BOOLEAN is 
  56.       local
  57.      call: CALL;
  58.      rf6: RUN_FEATURE_6;
  59.       do
  60.      if left_side.is_result then
  61.         if right_side.is_pre_computable then
  62.            call ?= right_side;
  63.            if call /= Void then
  64.           rf6 ?= call.run_feature;
  65.           Result := rf6 = Void;
  66.            else
  67.           Result := true;
  68.            end;
  69.         end;
  70.      end;
  71.       end;
  72.    
  73.    afd_check is
  74.       do
  75.      right_side.afd_check;
  76.       end;
  77.  
  78.    compile_to_c is
  79.       local
  80.      left_run_type, right_run_type: TYPE;
  81.      trace: BOOLEAN;
  82.       do
  83.      trace := trace_instruction;
  84.      if trace then
  85.         cpp.rs_push_position('1',start_position);
  86.      end;
  87.      left_run_type := left_type.run_type;
  88.      right_run_type := right_type.run_type;
  89.      if left_run_type.is_reference then
  90.         if right_run_type.is_reference then
  91.            -- ------------------------ Reference into Reference :
  92.            left_side.compile_to_c;
  93.            cpp.put_character('=');
  94.            if right_side.is_current then
  95.           cpp.put_string(fz_cast_t0_star);
  96.            end;
  97.            right_side.compile_to_c;
  98.            cpp.put_string(fz_00);
  99.         else
  100.            -- ------------------------- Expanded into Reference :
  101.            left_side.compile_to_c;
  102.            cpp.put_character('=');
  103.            right_run_type.to_reference;
  104.            cpp.put_character('(');
  105.            right_side.compile_to_c;
  106.            cpp.put_character(')');
  107.            cpp.put_string(fz_00);
  108.         end;
  109.      else
  110.         check
  111.            left_run_type.is_expanded
  112.         end;
  113.         if right_run_type.is_reference then
  114.            -- ------------------------- Reference into Expanded :
  115.            -- (std_copy or fail when Void).
  116.            eh.add_position(left_side.start_position);
  117.            fatal_error("Not Yet Implemented %
  118.                %(ASSIGNMENT/Reference into Expanded).");
  119.         else
  120.            -- -------------------------- Expanded into Expanded :
  121.            if left_run_type.is_bit then
  122.           bit_into_bit(left_run_type,right_run_type);
  123.            else
  124.           c_coding1;
  125.            end;
  126.         end;
  127.      end;
  128.      if trace then
  129.         cpp.rs_pop_position;
  130.      end;
  131.       end;
  132.    
  133.    compile_to_jvm is
  134.       do
  135.      left_side.compile_to_jvm_assignment(Current);
  136.       end;
  137.    
  138.    use_current: BOOLEAN is
  139.       do
  140.      Result := left_side.use_current;
  141.      Result := Result or else right_side.use_current;
  142.       end;
  143.       
  144.    right_type: TYPE is
  145.       require
  146.      right_side.is_checked
  147.       do
  148.      Result := right_side.result_type;
  149.       ensure
  150.      Result /= Void
  151.       end;
  152.    
  153.    left_type: TYPE is
  154.       do
  155.      Result := left_side.result_type;
  156.       ensure
  157.      Result /= Void
  158.       end;
  159.    
  160.    start_position: POSITION is
  161.       do
  162.      Result := left_side.start_position;
  163.       end;
  164.    
  165.    to_runnable(rc: like run_compound): like Current is
  166.       local
  167.      left_run_type, right_run_type: TYPE;
  168.      e: EXPRESSION;
  169.       do
  170.      if run_compound = Void then
  171.         run_compound := rc;
  172.         e := left_side.to_runnable(current_type);
  173.         if e = Void then
  174.            error(left_side.start_position,fz_blhsoa);
  175.         else
  176.            left_side := e;
  177.         end;
  178.         e := right_side.to_runnable(current_type);
  179.         if e = Void then
  180.            error(right_side.start_position,fz_brhsoa);
  181.         else
  182.            right_side := e;
  183.         end;
  184.         if nb_errors = 0 then
  185.            if not right_side.is_a(left_side) then
  186.           error(left_side.start_position," Bad assignment.");
  187.            end;
  188.         end;
  189.         if nb_errors = 0 then
  190.            left_run_type := left_type.run_type;
  191.            right_run_type := right_type.run_type;
  192.            if left_run_type.is_reference then
  193.           if right_run_type.is_reference then
  194.              -- ------------------------- Reference into Reference :
  195.           else
  196.              -- -------------------------- Expanded into Reference :
  197.              right_run_type.used_as_reference;
  198.           end;
  199.            else
  200.           if right_run_type.is_reference then
  201.              -- -------------------------- Reference into Expanded :
  202.              if right_side.is_void then
  203.             eh.add_position(right_side.start_position);
  204.             eh.append("Void may not be assigned to an %
  205.                   %expanded entity. Left hand side is ");
  206.             eh.add_type(left_type,".");
  207.             eh.print_as_error;
  208.              else
  209.             warning(left_side.start_position,
  210.                 "ASSIGNMENT/Not Yet Implemented.");
  211.              end;
  212.           else
  213.              -- --------------------------- Expanded into Expanded :
  214.           end;
  215.            end;
  216.         end;
  217.         if nb_errors = 0 then
  218.            Result := Current;
  219.         end;
  220.      else
  221.         !!Result.make(left_side,right_side);
  222.         Result := Result.to_runnable(rc);
  223.      end;
  224.       end;
  225.    
  226.    pretty_print is
  227.       do
  228.      pretty_print_assignment(left_side,":=",right_side);
  229.       end;
  230.  
  231. feature {NONE}
  232.  
  233.    c_coding1 is
  234.       do
  235.      left_side.compile_to_c;
  236.      cpp.put_character('=');
  237.      right_side.compile_to_c;
  238.      cpp.put_string(fz_00);
  239.       end;
  240.  
  241.    bit_into_bit(left_t, right_t: TYPE) is
  242.       require
  243.      left_t.is_bit;
  244.      right_t.is_bit
  245.       local 
  246.      left, right: TYPE_BIT;
  247.       do
  248.      left ?= left_t;
  249.      right ?= right_t;
  250.      if left.is_c_char then -- ------- unsigned char <- unsigned char
  251.         if left.nb = right.nb then
  252.            c_coding1;
  253.         else
  254.            left_side.compile_to_c;
  255.            cpp.put_character('=');
  256.            right_side.compile_to_c;
  257.            cpp.put_string(fz_c_shift_right);
  258.            cpp.put_integer(left.nb - right.nb);
  259.            cpp.put_string(fz_00);
  260.         end;
  261.      elseif left.is_c_int then 
  262.         if right.is_c_int then -- ------------- unsigned <- unsigned
  263.            if left.nb = right.nb then
  264.           c_coding1; 
  265.            else
  266.           left_side.compile_to_c;
  267.           cpp.put_character('=');
  268.           right_side.compile_to_c;
  269.           cpp.put_string(fz_c_shift_right);
  270.           cpp.put_integer(left.nb - right.nb);
  271.           cpp.put_string(fz_00);
  272.            end;
  273.         else  -- ----------------------------------- unsigned <- unsigned char
  274.            check
  275.           right.is_c_char
  276.            end;
  277.            left_side.compile_to_c;
  278.            cpp.put_string("=((unsigned)");
  279.            right_side.compile_to_c;
  280.            cpp.put_string(")<<((CHAR_BIT*sizeof(unsigned))-CHAR_BIT-(");
  281.            cpp.put_integer(left.nb);
  282.            cpp.put_character('-');
  283.            cpp.put_integer(right.nb);
  284.            cpp.put_string(fz_16);
  285.         end;
  286.      else 
  287.         check 
  288.            left.is_c_unsigned_ptr
  289.         end;
  290.         if right.is_c_unsigned_ptr then -- -- unsigned* <- unsigned*
  291.            cpp.put_string("memcpy(");
  292.            left_side.mapping_c_arg(left);
  293.            cpp.put_character(',');
  294.            right_side.mapping_c_arg(right);
  295.            cpp.put_character(',');
  296.            cpp.put_integer(left.space_for_variable);
  297.            cpp.put_character(')');
  298.            cpp.put_string(fz_00);
  299.         elseif right.is_c_int then -- ------- unsigned* <- unsigned
  300.            cpp.put_string("memset(&"); 
  301.            left_side.compile_to_c;
  302.            cpp.put_string(",0,sizeof(");
  303.            left_side.compile_to_c;
  304.            cpp.put_string(fz_16);
  305.         else -- -------------